package com.bos.model;

import com.bos.domain.Instansi;
import com.bos.domain.Jabatan;
import com.bos.domain.Pengelola;
import com.bos.domain.Role;

/**
 * Created by IntelliJ IDEA.
 * User: Latief
 * Date: 3/12/11
 * Time: 2:28 PM
 * To change this template use File | Settings | File Templates.
 */
public class PengelolaRequest {

    private long id;
    private String nama;
    private String telp;
    private Instansi instansi;
    private Jabatan jabatan;
    private String username;
    private String password;
    private String salt;
    private Role role;
    private boolean enabled;

    public PengelolaRequest() {
    }

    public PengelolaRequest(Pengelola pengelola) {
        compareFrom(pengelola);
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public String getTelp() {
        return telp;
    }

    public void setTelp(String telp) {
        this.telp = telp;
    }

    public Instansi getInstansi() {
        return instansi;
    }

    public void setInstansi(Instansi instansi) {
        this.instansi = instansi;
    }

    public Jabatan getJabatan() {
        return jabatan;
    }

    public void setJabatan(Jabatan jabatan) {
        this.jabatan = jabatan;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public void compareFrom(Pengelola pengelola){
        setEnabled(pengelola.isEnabled());
        setId(pengelola.getId());
        setInstansi(pengelola.getInstansi());
        setJabatan(pengelola.getJabatan());
        setNama(pengelola.getNama());
        setPassword(pengelola.getPassword());
        setRole(pengelola.getRole());
        setSalt(pengelola.getSalt());
        setTelp(pengelola.getTelp());
        setUsername(pengelola.getUsername());
    }

    public Pengelola convertTo(){
        Pengelola pengelola = new Pengelola();
        pengelola.setEnabled(isEnabled());
        pengelola.setId(getId());
        pengelola.setInstansi(getInstansi());
        pengelola.setJabatan(getJabatan());
        pengelola.setNama(getNama());
        pengelola.setPassword(getPassword());
        pengelola.setRole(getRole());
        pengelola.setSalt(getSalt());
        pengelola.setTelp(getTelp());
        pengelola.setUsername(getUsername());
        return pengelola;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PengelolaRequest)) return false;

        PengelolaRequest that = (PengelolaRequest) o;

        if (enabled != that.enabled) return false;
        if (id != that.id) return false;
        if (instansi != null ? !instansi.equals(that.instansi) : that.instansi != null) return false;
        if (jabatan != null ? !jabatan.equals(that.jabatan) : that.jabatan != null) return false;
        if (nama != null ? !nama.equals(that.nama) : that.nama != null) return false;
        if (password != null ? !password.equals(that.password) : that.password != null) return false;
        if (role != null ? !role.equals(that.role) : that.role != null) return false;
        if (salt != null ? !salt.equals(that.salt) : that.salt != null) return false;
        if (telp != null ? !telp.equals(that.telp) : that.telp != null) return false;
        if (username != null ? !username.equals(that.username) : that.username != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = (int) (id ^ (id >>> 32));
        result = 31 * result + (nama != null ? nama.hashCode() : 0);
        result = 31 * result + (telp != null ? telp.hashCode() : 0);
        result = 31 * result + (instansi != null ? instansi.hashCode() : 0);
        result = 31 * result + (jabatan != null ? jabatan.hashCode() : 0);
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (salt != null ? salt.hashCode() : 0);
        result = 31 * result + (role != null ? role.hashCode() : 0);
        result = 31 * result + (enabled ? 1 : 0);
        return result;
    }

    @Override
    public String toString() {
        return "PengelolaRequest{" +
                "id=" + id +
                ", nama='" + nama + '\'' +
                ", telp='" + telp + '\'' +
                ", instansi=" + instansi +
                ", jabatan=" + jabatan +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", salt='" + salt + '\'' +
                ", role=" + role +
                ", enabled=" + enabled +
                '}';
    }
}
